import java.util.LinkedList;
import java.util.List;



public class Vertex {
	private String name; // Vertex name
	private List<Edge> outgoingEdges; 
	private List<Edge> incEdges;
	private double earliestTime;
	private double lastTime;
	private boolean vertexPassed;
	
	public Vertex( String n){
		name = n; 
		outgoingEdges = new LinkedList<Edge>( ); 
		incEdges = new LinkedList<Edge>();
		earliestTime = -Double.MAX_VALUE;
		lastTime = Double.MAX_VALUE;
		vertexPassed = false;
	}

	public void addOutgoingEdge(Edge newEdge){
		outgoingEdges.add(newEdge);
	}
	
	public void addIncomingEdge(Edge newEdge){
		incEdges.add(newEdge);
	}

	public String getName(){
		return name;
	}

	public double getEarliestTime(){
		return earliestTime;
	}

	public double getLastTime(){
		return lastTime;
	}
	
	public boolean vertexPassed(){
		return vertexPassed;
	}

	public void setVertexPassed(){
		vertexPassed = true;
	}
	
	public void resetVertexPassed(){
		vertexPassed = false;
	}

	public List<Edge> getOutgoingEdges(){
		return outgoingEdges;
	}
	
	public List<Edge> getIncomingEdges(){
		return incEdges;
	}

	public double getCostToNeighbour(Vertex toVertex){
		for (Edge edge : outgoingEdges){
			if (toVertex == edge.getDestination()){
				return edge.getWeight();
			}
		}

		return Double.MIN_VALUE;
	}

	public void setEearliestTime(double newTime){
		earliestTime = newTime;
	}

	public void setLastTime(double newTime){
		lastTime = newTime;
	}
	
	public boolean hasPredecessors(){
		// if there are no inc edges
		if (incEdges.isEmpty()){
			return false;
		}
		// if there are any active edges left there are predecessors
		for (Edge edge : incEdges){
			if (!edge.getStart().vertexPassed()){
				return true;
			}
		}
		
		// if there are no active edges left there are no predecessors
		return false;
	}
	
	

	

}

